package com.heima.studentinfoplus.controller;

import com.heima.studentinfoplus.entity.ApiResponse;
import com.heima.studentinfoplus.entity.StudentProfile;
import com.heima.studentinfoplus.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @GetMapping("/profile")
    public ResponseEntity<ApiResponse> getStudentProfile() {
        // 从请求头中获取 token
        String token = getTokenFromRequest(); // 需要实现这个方法来获取 token

        // 调用服务层获取学生信息
        StudentProfile profile = studentService.getStudentProfile(token);

        // 构建响应体
        ApiResponse response = new ApiResponse(0, profile);

        return ResponseEntity.ok(response);
    }

    private String getTokenFromRequest() {
        // 实际项目中从 HttpServletRequest 获取 token
        return "mock-token"; // 示例代码
    }
}
